import java.io.*;
import java.util.Scanner;

public class Test4 {
    private static void copy1(File sourceFile,File aimFile){
        try (InputStream inputStream = new FileInputStream(sourceFile);
             OutputStream outputStream = new FileOutputStream(aimFile)){
            while (true){
                int len = inputStream.read();
                if (len == -1){
                    break;
                }
                System.out.printf("%c",len);
                outputStream.write(len);
            }
            System.out.println("复制完成");
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    private static void copy(File sourceFile,File aimFile){
        try (InputStream inputStream = new FileInputStream(sourceFile);
             OutputStream outputStream = new FileOutputStream(aimFile)){
            while (true){
                int len = inputStream.read();
                if (len == -1){
                    break;
                }
                System.out.printf("%c",len);
                outputStream.write(len);
            }
            System.out.println("复制完成");
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入被复制文件的路径 (绝对路径)");
        String source = scanner.next();
        File sourceFile = new File(source);
        if (!sourceFile.exists()){
            System.out.println("路径文件不存在,程序退出");
        }
        System.out.println("请输入文件将要复制到的路径 (绝对路径)");
        String aim = scanner.next();
        File aimFile = new File(aim);
        if (aimFile.exists()){
            System.out.println("目标文件已存在 程序退出");
        }
        copy(sourceFile,aimFile);
    }
}